
//此处的'sequenceController'要与app.js里的对应的$stateProvider.state(中的 controller对应的值一致
colorAdminApp.controller('sequenceController', function($scope,$compile,$rootScope,$http,$state,$stateParams,modalService) {
	
	//分页初始化参数
	$scope.easyNgPagination={
			options:{
				        currentPage:1,
				        totalCount:0,
				        pageSize:10,
			            onPageChange: function(){
			 		            	$scope.loadData();
			            }
			}
	};
	//用来显示的查询结果集
	$scope.items=[];
	//加载查询结果数据
	$scope.loadData=function(){
		//当前页
		var currentPage=$scope.easyNgPagination.options.currentPage-1;
		//查询参数
		var entity={"name":$scope.q.name,"page":currentPage,"size":$scope.easyNgPagination.options.pageSize};
        //遮罩层
		$(".dataTables_wrapper").block({ message:'正在加载数据，请稍等...',css: { top: '50%' } });
		//http请求
        $http.post('api/core/configuration/sequence/findByPage',{params:entity}).success(function(data, status, headers, config) {
			//把请求结果的内容传递给用来显示的查询结果集
        	$scope.items=data.data.content;
        	//重新设置总条数
			$scope.easyNgPagination.options.totalCount=data.data.totalElements;
			//关闭遮罩层
			$(".dataTables_wrapper").unblock();
		}).error(function(data, status, headers, config) {
	    	
        });  
	};
	
	/**
	 * 显示编辑窗口
	 */
	$scope.showEditModal=function(entity){
		$scope.editEntity=entity;
		$("#editModal").modal("show");	
	};
	/**
	 * 显示新建窗口
	 */
	$scope.showAddModal=function(){
		$("#addModal").modal("show");	
	};
	
	$scope.entity={};
	$scope.q={"name":""};
	
	/**
	 * 更新
	 */
	$scope.update=function(entity){
		delete entity.createTime;
		delete entity.updateTime;
		var requestJson=JSON.stringify(entity);
		$(".modal-dialog").block({message:'正在执行操作，请稍等...'});
		$http.post('api/core/configuration/sequence/update',{params:{"requestJson":requestJson}}).success(function(data, status, headers, config) {
			$(".modal-dialog").unblock();
			modalService.showAlertModal('注意',data.message);
			if(data.status==1){
				$("#editModal").modal("hide");
				$scope.loadData();
			}
		}).error(function(data, status, headers, config) {
	    	
        });  
	};
	/**
	 * 新建保存
	 */
    $scope.save=function(entity){
    	var requestJson=JSON.stringify(entity);
   		$(".modal-dialog").block({message:'正在执行操作，请稍等...'});
		$http.post('api/core/configuration/sequence/add',{params:{"requestJson":requestJson}}).success(function(data, status, headers, config) {
			$(".modal-dialog").unblock();
			modalService.showAlertModal('注意',data.message);
			if(data.status==1){
				$("#addModal").modal("hide");
				$scope.loadData();
			}
		}).error(function(data, status, headers, config) {
	    	
        });  
	};
	/**
	 * 删除
	 */
	$scope.doDelete=function(item){
		if(!confirm("确认删除 “" + item.name + "” 吗？")){
			return ;
		}
		$("body").block({ message:'正在执行操作，请稍等...',css: { top: '50%' } });
		$http.post('api/core/configuration/sequence/deleteById',{params:{"id":item.id}}).success(function(data, status, headers, config) {
			modalService.showAlertModal('注意',data.message);
			$("body").unblock();
			if(data.status==1){
				$scope.loadData(); 
			}
		}).error(function(data, status, headers, config) {
			$("body").unblock();
	    	
       });  
	};
	
	
    
	
    
	
});
